<%@ page language="java" import="com.alibaba.fastjson.JSONObject" pageEncoding="UTF-8" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.math.BigDecimal" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<%--用款流程关联合同流程清单--%>
<%
    String requestid = Util.null2String(request.getParameter("requestid"));
    Map<String, Object> apidatas = new HashMap<String, Object>();
    String code = "SUCCESS";
    String message = "";
    try {
        RecordSet rs = new RecordSet();
        rs.executeQuery("select abs(formid) formid from workflow_base a join workflow_requestbase b on a.id=b.workflowid where b.requestid =?",requestid);
        rs.next();
        String formid = Util.null2String(rs.getString(1));
        rs.executeQuery("select * from formtable_main_"+formid+" where requestid=?",requestid);
        rs.next();
        String spbh = Util.null2String(rs.getString("spbh"));
        String htbh = Util.null2String(rs.getString("htbh"));
        htbh = spbh+htbh;
        String htzje = Util.null2String(rs.getString("htzje"));
        String htksrq = Util.null2String(rs.getString("htksrq"));
        String htjsrq = Util.null2String(rs.getString("htjsrq"));
        String htje = Util.null2String(rs.getString("htje"),"0");
        htje = fMultiply(htje,"10000",2);
        JSONObject dataJson = new JSONObject();
        dataJson.put("htbh",htbh);
        dataJson.put("htzje",htzje);
        dataJson.put("htksrq",htksrq);
        dataJson.put("htjsrq",htjsrq);
        dataJson.put("htje",htje);
        apidatas.put("data", dataJson);
    } catch (Exception e) {
        e.printStackTrace();
        code = "SYSTEM_INNER_ERROR";
        message = "程序内部异常";
    }
    apidatas.put("code", code);
    apidatas.put("message", message);
    out.print(JSONObject.toJSONString(apidatas));

%>
<%!

    // 乘法保留小数位
    public static String fMultiply(String a, String b,int n) {
        a = isZero(a);
        b = isZero(b);
        BigDecimal bg1 = new BigDecimal(a);
        BigDecimal bg2 = new BigDecimal(b);

        BigDecimal bd = bg1.multiply(bg2).setScale(n, BigDecimal.ROUND_HALF_UP);
        return bd.toString();
    }
    public static String isZero(String a) {
        if ("".equals(a)) {
            a = "0";
        }
        return a;
    }
%>



